package com.shop2cn.iapi.agentproducts.testcase;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.collections.ArrayStack;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.shop2cn.iapi.agentproducts.parameter.SetConditionTypeBean;
import com.shop2cn.iapi.agentproducts.parameter.rebate.ConditionTypeDto;
import com.shop2cn.iapi.agentproducts.service.SetConditionTypeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;

/**
*设置返佣条件类型权重Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SetConditionType{
	private static SetConditionTypeBean setconditiontypeBean;
	private static SetConditionTypeCall setconditiontypeCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置返佣条件类型权重Test");
	}

	@Before
	public void caseUp() {
		setconditiontypeBean=new SetConditionTypeBean();
		setconditiontypeCall=new SetConditionTypeCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(setconditiontypeCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetConditionType_001() {
		Logger.start(true,"随机设置一个权重，成功");
		try {
			Integer userId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			setconditiontypeBean.setUserId(userId);
			setconditiontypeBean.setConditionTypeList(initConditionTypeList());
			setconditiontypeCall.setData(setconditiontypeBean);
			setconditiontypeCall.callService();			
			Logger.verifyEquals("200", setconditiontypeCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetConditionType_002() {
		Logger.start(true,"条件不全，失败");
		try {
			Integer userId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			setconditiontypeBean.setUserId(userId);
			List<ConditionTypeDto> initConditionTypeList = initConditionTypeList();
			initConditionTypeList.remove(0);
			setconditiontypeBean.setConditionTypeList(initConditionTypeList);
			setconditiontypeCall.setData(setconditiontypeBean);
			setconditiontypeCall.callService();			
			Logger.verifyEquals("201", setconditiontypeCall.getString("code"), "验证code");
			Logger.verifyEquals("未完整设置优先级策略", setconditiontypeCall.getString("message"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetConditionType_003() {
		Logger.start(true,"条件多了一个,失败");
		try {
			Integer userId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			setconditiontypeBean.setUserId(userId);
			List<ConditionTypeDto> initConditionTypeList = initConditionTypeList();
			initConditionTypeList.add(new ConditionTypeDto(1, 7));
			setconditiontypeBean.setConditionTypeList(initConditionTypeList);
			setconditiontypeCall.setData(setconditiontypeBean);
			setconditiontypeCall.callService();			
			Logger.verifyEquals("201", setconditiontypeCall.getString("code"), "验证code");
			Logger.verifyEquals("未完整设置优先级策略", setconditiontypeCall.getString("message"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore//不用校验
	public void Tc_SetConditionType_004() {
		Logger.start(true,"用户id无效。失败");
		try {
			Integer userId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			setconditiontypeBean.setUserId(1122334455);
			List<ConditionTypeDto> initConditionTypeList = initConditionTypeList();
			setconditiontypeBean.setConditionTypeList(initConditionTypeList);
			setconditiontypeCall.setData(setconditiontypeBean);
			setconditiontypeCall.callService();			
			Logger.verifyEquals("201", setconditiontypeCall.getString("code"), "验证code");
			Logger.verifyEquals("未完整设置优先级策略", setconditiontypeCall.getString("message"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetConditionType_006() {
		Logger.start(true,"有两个条件不变动");
		try {
			Integer userId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			setconditiontypeBean.setUserId(1122334455);
			List<ConditionTypeDto> initConditionTypeList = initConditionTypeList();
			initConditionTypeList.set(0, new ConditionTypeDto(1, 1));
			initConditionTypeList.set(6, new ConditionTypeDto(7, 7));
			setconditiontypeBean.setConditionTypeList(initConditionTypeList);
			setconditiontypeCall.setData(setconditiontypeBean);
			setconditiontypeCall.callService();			
			Logger.verifyEquals("200", setconditiontypeCall.getString("code"), "验证code");
			Logger.verifyEquals("操作成功", setconditiontypeCall.getString("message"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	private List<ConditionTypeDto> initConditionTypeList(){
		List<ConditionTypeDto> asList = new ArrayList<ConditionTypeDto>();
		for (int i = 1; i <8; i++) {
				ConditionTypeDto conditionTypeDto = new ConditionTypeDto();
				conditionTypeDto.setConditionType(i);
				conditionTypeDto.setWeight(8-i);
				asList.add(conditionTypeDto);
		}
		return asList;
	}
}